/*
 * Copyright 2002-2021 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.aop;

import org.aopalliance.aop.Advice;

/**
 * Subinterface of AOP Alliance Advice that allows additional interfaces
 * to be implemented by an Advice, and available via a proxy using that
 * interceptor. This is a fundamental AOP concept called <b>introduction</b>.
 *
 * <p>Introductions are often <b>mixins</b>, enabling the building of composite
 * objects that can achieve many of the goals of multiple inheritance in Java.
 *
 * <p>Compared to {@link IntroductionInfo}, this interface allows an advice to
 * implement a range of interfaces that is not necessarily known in advance.
 * Thus an {@link IntroductionAdvisor} can be used to specify which interfaces
 * will be exposed in an advised object.
 *
 * @author Rod Johnson
 * @since 1.1.1
 * @see IntroductionInfo
 * @see IntroductionAdvisor
 */
/*
1. 总结
DynamicIntroductionAdvice 是 Spring AOP 中用于动态引入接口的标记接口
它继承自 AOP Alliance 的 Advice 接口，扩展了 introduction（引入）功能
允许在运行时动态决定 Advice 是否实现某个特定接口，提供比静态引入更灵活的接口暴露机制

2 内部成员
boolean implementsInterface(Class<?> intf)：判断该引入通知是否实现了指定接口，用于在运行时动态检查 Advice 是否支持某个特定接口，为代理对象的接口暴露提供依据

3. 类和接口关系

    Advice	AOP 联盟定义的根标记接口，表示通知（增强）的通用概念，不包含任何方法
     ├── Interceptor	标记接口，用于拦截方法调用
     │   ├── ConstructorInterceptor  构造器拦截器，用于拦截构造器调用
     │   └── MethodInterceptor	方法拦截器，可以在方法调用前后执行自定义逻辑
     │      ├── IntroductionInterceptor
     │      │     ├── DelegatePerTargetObjectIntroductionInterceptor
     │  	│     └──  DelegatingIntroductionInterceptor
     │      └── ...
     └── DynamicIntroductionAdvice	动态引入接口，用于向目标对象动态添加新的接口和实现
         └── IntroductionInterceptor 标记接口，用于动态引入新的接口和实现到目标对象
             ├── DelegatePerTargetObjectIntroductionInterceptor	委托引入拦截器，通过委托给特定对象实现引入的接口
         	 └──  DelegatingIntroductionInterceptor

	DynamicIntroductionAdvice：支持运行时动态决定实现哪些接口的引入通知接口
	IntroductionInfo：静态引入接口信息，需要预先知道要引入的所有接口
	IntroductionAdvisor：引入顾问接口，用于指定哪些接口将通过引入通知暴露
	IntroductionInterceptor：引入拦截器，是 DynamicIntroductionAdvice 的具体实现接口
4. 使用场景
	需要在运行时动态决定为代理对象添加哪些接口
	实现类似多重继承的功能，通过 mixin 模式构建复合对象
	在不修改原有类的情况下，为对象动态添加新的行为和状态
	构建灵活的、可配置的对象增强机制
5. 实际代码应用示例
// 自定义 DynamicIntroductionAdvice 实现
public class MyDynamicIntroductionAdvice extends DelegatingIntroductionInterceptor
    implements DynamicIntroductionAdvice {

    private Set<Class<?>> supportedInterfaces = new HashSet<>();

    public MyDynamicIntroductionAdvice() {
        supportedInterfaces.add(Lockable.class);
        supportedInterfaces.add(Modifiable.class);
    }

    @Override
    public boolean implementsInterface(Class<?> intf) {
        return supportedInterfaces.contains(intf);
    }
}

// 使用示例
ProxyFactory proxyFactory = new ProxyFactory(targetObject);
proxyFactory.addAdvisor(new DefaultIntroductionAdvisor(new MyDynamicIntroductionAdvice()));
Lockable lockableProxy = (Lockable) proxyFactory.getProxy();

 */
public interface DynamicIntroductionAdvice extends Advice {

	/**
	 * Does this introduction advice implement the given interface?
	 * @param intf the interface to check
	 * @return whether the advice implements the specified interface
	 */
	boolean implementsInterface(Class<?> intf);

}
